package com.faya.green.utils;

import cn.hutool.cache.CacheUtil;
import cn.hutool.cache.impl.TimedCache;
import com.github.pagehelper.PageHelper;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * 用户 ：LX
 * 创建时间： 2018/7/11. 0:31
 * 地点：广州
 * 目的: 公共的方法
 * 结果：
 */
public class CommonUtils {

    /**
     * null验证
     * @param str 待验证的字符串
     * @return true 是空  false 不是空
     */
    public static boolean checkNull(String str){
        if (str == null || "".equals(str) || "undefined".equals(str) || "null".equals(str)){
            return true;
        } else {
            return false;
        }
    }

    /**
     * 生成去掉“-”的树形uuid  总长度32位
     * @return
     */
    public static String getUUID(){
        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        return uuid;
    }

    /**
     * 获取request
     * @return
     */
    public static HttpServletRequest getRequest(){
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)attributes;
        return servletRequestAttributes.getRequest();
    }

    /**
     * 获取session
     * @return
     */
    public static HttpSession getSession(){
        HttpSession session = getRequest().getSession();
        return session;
    }


    /**
     * 生成 Timestamp 时间
     * @return
     */
    public static Timestamp getTimestamp(){
        return new Timestamp(System.currentTimeMillis());
    }


}
